import fetch from 'node-fetch';

async function testDeleteEmptyCategory() {
    console.log('🧪 测试删除没有关联文章的分类\n');
    
    const baseUrl = 'http://localhost:8000/api/v1/admin';
    const authToken = 'Bearer admin_token';
    
    try {
        // 测试删除ID为9的分类（可能没有关联文章）
        console.log('🔥 测试: 删除ID为9的分类');
        const response = await fetch(`${baseUrl}/category/delete`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': authToken
            },
            body: JSON.stringify({ id: 9 })
        });
        const result = await response.json();
        console.log(`状态码: ${response.status}`);
        console.log(`响应: ${JSON.stringify(result)}\n`);
        
        // 验证删除结果：再次查询该分类
        if (result.code === 200 && result.msg === "删除成功") {
            console.log('✅ 删除成功！验证分类是否真的被删除...');
            const checkResponse = await fetch(`${baseUrl}/category/search?id=9`, {
                method: 'GET',
                headers: {
                    'Authorization': authToken
                }
            });
            const checkResult = await checkResponse.json();
            console.log(`验证结果: ${JSON.stringify(checkResult)}`);
        }
        
    } catch (error) {
        console.error('测试失败:', error.message);
    }
}

testDeleteEmptyCategory();
